﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ExportManager
{
    /// <summary>
    /// Interaction logic for RunExports.xaml
    /// </summary>
    public partial class RunExports : Window
    {
        private List<Int32> _exportIDs;

        public RunExports(List<Int32> exportIDs)
        {
            InitializeComponent();
            _exportIDs = exportIDs;
        }

        private void btnRun_Click(object sender, RoutedEventArgs e)
        {
            string CommandText = "Exporter StartDate=" + cmbStartDate.SelectedDate.ToString() +
                " EndDate=" + cmbEndDate.SelectedDate.ToString();
            foreach (Int32 exportID in _exportIDs)
                CommandText += " ExportID=" + exportID.ToString();

            System.Diagnostics.Process process = System.Diagnostics.Process.Start(CommandText);

            // Wait for the export to finish.
            Cursor tempCursor = Cursor;
            Cursor = Cursors.Wait;
            process.WaitForExit();
            Cursor = tempCursor;
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            cmbEndDate.SelectedDate = DateTime.Today;
            cmbStartDate.SelectedDate = DateTime.Today;
        }
    }
}
